package com.medicine.web.controller.manage;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.medicine.common.annotation.Log;
import com.medicine.common.core.controller.BaseController;
import com.medicine.common.core.domain.AjaxResult;
import com.medicine.common.enums.BusinessType;
import com.medicine.manage.domain.MedicinalPan;
import com.medicine.manage.service.IMedicinalPanService;
import com.medicine.common.utils.poi.ExcelUtil;
import com.medicine.common.core.page.TableDataInfo;

/**
 * 煎药锅管理Controller
 * 
 * @author admin
 * @date 2024-10-12
 */
@RestController
@RequestMapping("/manage/medicinePan")
public class MedicinalPanController extends BaseController
{
    @Autowired
    private IMedicinalPanService medicinalPanService;

    /**
     * 查询煎药锅管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MedicinalPan medicinalPan)
    {
        startPage();
        List<MedicinalPan> list = medicinalPanService.selectMedicinalPanList(medicinalPan);
        return getDataTable(list);
    }

    /**
     * 导出煎药锅管理列表
     */
    @Log(title = "煎药锅管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicinalPan medicinalPan)
    {
        List<MedicinalPan> list = medicinalPanService.selectMedicinalPanList(medicinalPan);
        ExcelUtil<MedicinalPan> util = new ExcelUtil<MedicinalPan>(MedicinalPan.class);
        util.exportExcel(response, list, "煎药锅管理数据");
    }

    /**
     * 获取煎药锅管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(medicinalPanService.selectMedicinalPanById(id));
    }

    /**
     * 新增煎药锅管理
     */
    @Log(title = "煎药锅管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicinalPan medicinalPan)
    {
        if(!this.medicinalPanService.checkUnique(medicinalPan.getPanNumber(), medicinalPan.getDeptId())){
            return error("新增煎药锅'" + medicinalPan.getPanNumber() + "'失败，煎药锅编号已存在");
        }
        return toAjax(medicinalPanService.insertMedicinalPan(medicinalPan));
    }

    /**
     * 修改煎药锅管理
     */
    @Log(title = "煎药锅管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicinalPan medicinalPan)
    {
        if(!this.medicinalPanService.checkUnique(medicinalPan.getPanNumber(), medicinalPan.getDeptId())){
            return error("更新煎药锅'" + medicinalPan.getPanNumber() + "'失败，煎药锅编号已存在");
        }
        return toAjax(medicinalPanService.updateMedicinalPan(medicinalPan));
    }

    /**
     * 删除煎药锅管理
     */
    @Log(title = "煎药锅管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(medicinalPanService.deleteMedicinalPanByIds(ids));
    }
}
